package com.umeox.watch.moto.launcher.ui;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.KeyEvent;
import android.view.View;
import android.view.WindowManager;

import com.umeox.moto.common.log.Logger;
import com.umeox.moto.watch.themes.app.ThemeAppCompatActivity;
import com.umeox.watch.moto.dataservice.DataProvider;
import com.umeox.watch.moto.launcher.R;


public class NetworkNormalActivity extends ThemeAppCompatActivity {
    Handler mHandler = new Handler();
    private boolean mIsActivated;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_net_normal);
        mIsActivated = DataProvider.isActivated();
        Logger.e("NetworkNormalActivity","mIsActivated=" + mIsActivated);
        mHandler.postDelayed(() -> launch(null), 2000);
    }

    public void launch(View view) {
        mHandler.removeCallbacksAndMessages(null);
        if (mIsActivated) { //绑定了
            startMainActivity();
        } else {
            QrActivity.launch(this);
        }
        finish();
    }

    private void startMainActivity() {
        Intent intent = new Intent(NetworkNormalActivity.this, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
        startActivity(intent);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }


    @Override
    protected void registerUnbindAndDisableReceiver(boolean register) {
    }
}
